package com.buercorp.wangyu.socket.tcpdemo04;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 本地文件上传 线程
 * 客户端：将本地文件上传到服务器 接收服务器的反馈
 * 服务器：接收客户端上传的文件 上传完毕之后给出反馈
 *
 * @author liyiyu
 */
public class Server {
    public static void main(String[] args) throws IOException {
        // 绑定端口
        ServerSocket ss = new ServerSocket(13333);
        // 创建线程池对象
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                10,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        while (true) {
            // 等待客户端来连接
            Socket socket = ss.accept();
            // 开启一条线程
//            new Thread(new Myrunnable(socket)).start();
            // 线程池创建对象
            pool.submit(new Myrunnable(socket));
        }
    }
}
